﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Api;

namespace Portal.Modules.ImageBrowser
{
  [EditModule()]
  public partial class ModuleEditImageBrowser : Portal.StateBase.StateContainer<EditState, EditStateEvent>
  {
    # region Initialization of the state machine

    static ModuleEditImageBrowser()
    {
      // Add the available states.
      AddState(EditState.EditMenu, "StateEditMenu.ascx");
      AddState(EditState.EditModuleSettings, "StateEditModuleSettings.ascx");
      AddState(EditState.EditTexts, "StateEditTexts.ascx");
      
      // Add the transitions.
      AddTransition(EditState.EditMenu, EditStateEvent.EditModuleSettings, EditState.EditModuleSettings);
      AddTransition(EditState.EditModuleSettings, EditStateEvent.Back, EditState.EditMenu);
      AddTransition(EditState.EditMenu, EditStateEvent.EditTexts, EditState.EditTexts);
      AddTransition(EditState.EditTexts, EditStateEvent.Back, EditState.EditMenu);
    }

    # endregion

    protected void Page_Load(object sender, EventArgs e)
    {
      LoadCurrentCtrl(IsPostBack);
    }

    protected override int InitialStateKey
    {
      get
      {
        // Show the menu if the user is an admin. Otherwise start direct with the pictures editing.
        if (Page.User.IsInRole(Portal.Api.Config.AdminRole))
          return base.InitialStateKey;
        else
          return (int) EditState.EditTexts;
      }
    }
  }
}